package com.sti.platform.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aisino.core.common.JsonPost;
import com.aisino.core.controller.BaseController;
import com.sti.platform.model.Resource;
import com.sti.platform.service.ResourceService;

@Controller

@RequestMapping("resource")
public class ResourceController extends BaseController {
	
	@Autowired
	private ResourceService resourceService;
	
	@RequestMapping("index")
	public String resIndex(HttpServletRequest request){
		
		List<Resource> list=resourceService.get();
		
		request.setAttribute("message", list);
		
		return "resIndex";
	}
	
	@RequestMapping("add")
	public @ResponseBody Map add(final Resource resource){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){				
				map.put("message", resourceService.addResource(resource));
			}
		});
	}
	
	
	/*@RequestMapping("add")
	public String add(String name,String url,String code,String type,String isenable){
		
		log.info("name:"+name);
		
		
		return "resIndex";
	}*/

	
	@RequestMapping("addResource")
	public String addResource(Resource resource){
		
		log.info("name:"+resource.getName());
		
		resourceService.addResource(resource);
		
		return "resIndex";
	}

}
